package com.appcenter.application.controller;

import com.appcenter.application.input.jobCategory.*;
import com.appcenter.application.service.JobCategoryService;
import com.appcenter.jz.config.ErrorJsonResult;
import com.appcenter.jz.config.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/services/jzappcenter/jobcategory")
@Api("分类管理相关API")
public class JobCategoryController {
    @Autowired
    JobCategoryService jobCategoryService;

    @ApiOperation(value = "创建分类", notes = "创建分类", produces = "application/json")
    @PostMapping("/createjobcategory")
    public ResponseEntity<JsonResult> createJobCategory(@RequestBody CreateJobCategoryInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(jobCategoryService.CreateJobCategory (input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }



    @ApiOperation(value = "编辑分类", notes = "编辑分类", produces = "application/json")
    @PostMapping("/editjobcategory")
    public ResponseEntity<JsonResult> editJobCategory(@RequestBody EditJobCategoryInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(jobCategoryService.EditJobCategory(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "搜索分类", notes = "搜索分类", produces = "application/json")
    @PostMapping("/searchjobcategory")
    public ResponseEntity<JsonResult> searchJobCategory(@RequestBody SearchJobCategoryInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(jobCategoryService.SearchJobCategory(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
    @ApiOperation(value = "修改状态", notes = "修改状态", produces = "application/json")
    @PostMapping("/editjobcategorystatus")
    public ResponseEntity<JsonResult> editjobcategoryStatus(@RequestBody EditJobCategoryInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(jobCategoryService.EditJobCategoryStatus(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
    @ApiOperation(value = "删除分类", notes = "删除分类", produces = "application/json")
    @PostMapping("/deletejobcategory")
    public ResponseEntity<JsonResult> deletejobcategory(@RequestBody DeleteJobCategoryInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(jobCategoryService.DeleteJobCategory(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
}
